<template>
  <div>
    <home-header :city = "city"></home-header>
    <home-swiper :swiperList = "swiperList"></home-swiper>
    <home-icons :iconList="iconList"></home-icons>
    <home-recommend :recommendList = "recommendList"></home-recommend>
    <home-weeken :weekendList="weekendList"></home-weeken>
  </div>
</template>
<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/Recommend'
import HomeWeeken from './components/Weeken'
import axios from 'axios'
export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeeken
  },
  methods: {
    getHomeInfo () {
      axios.get('/api/index.json')
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.city = data.city
        this.swiperList = data.swiperList
        this.recommendList = data.recommendList
        this.iconList = data.iconList
        this.weekendList = data.weekendList
      }
    }
  },
  data () {
    return {
      city: ' ',
      swiperList: [],
      recommendList: [],
      iconList: [],
      weekendList: []
    }
  },
  mounted: function () {
    this.getHomeInfo()
  }
}
//	发送axios请求需要在static文件下创建mock文件，因为外部只能访问static文件
//	如果不需要上传这个mock文件可以在.gitignore中输入当前路径
//	同时在请求的时候不希望别人看到自己的路径通常使用api来代替
//	这是webpack提供了一个功能，存在一个转发的机制可以把对api下面的所有请求，转发到本地static中mock(自己建立的)
/*  文件下，即：点开config文件夹里的index.js文件，找到proxyTable更改成
	proxyTable: {
	target:https://localhost：8080,
	pathRewrite: {
	'^api': '/static/mock'}
	}
*/
</script>
<style>
</style>
